const http = require('http')
const url = require('url')
// const { createProxyMiddleware } = require('http-proxy-middleware')
const proxy1 = require('http-proxy-middleware')
const proxy=proxy1.createProxyMiddleware
const{createProxyMiddleware}= proxy
console.log(proxy)
const server = http.createServer((req, res) => {
    const urlstr = req.url
    if (/\/ajax/.test(urlstr)) {
        console.log(urlstr)
        const apiproxy = createProxyMiddleware('/api', {
            targrt: 'https://m.lagou.com',
            changeOrigin: true,           
        })
        apiproxy(req, res)
    }
    else {
        console.log('error')
    }
})
server.listen(8080, () => {
    console.log('localhost:8080')
})